package initialize

import (
	"awesomeProject/global"
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
)

func RedisInit() *redis.Client {
	redisCfg := global.Config.RedisConf
	client := redis.NewClient(&redis.Options{
		Addr:     redisCfg.Addr + ":" + redisCfg.Port,
		Password: redisCfg.Password, // no password set
		DB:       redisCfg.DB,       // use default DB
	})

	pong, err := client.Ping(context.Background()).Result()
	if err != nil {
		var errStr interface{}
		errStr = fmt.Sprint("redis connect ping failed, err:", err)
		panic(errStr)
	} else {
		fmt.Println("redis connect ping response:", pong)
		return client
	}
}
